package com.freedy.concurrent.Monitors.patterns;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.LockSupport;

/**
 * 同步模式之顺序控制
 * 固定顺序
 * 使用Park Unpack实现
 * @author Freedy
 * @date 2021/4/22 21:43
 */
@Slf4j
public class SequenceControlFixWithParkUnpack {
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            LockSupport.park(true);
            log.info("1");
        }, "t1");

        Thread t2 = new Thread(() -> {
            log.info("2");
            LockSupport.unpark(t1);
        }, "t2");

        t1.start();
        t2.start();
    }
}
